<?php 
require('common.inc.php');
header("Content-type:application/vnd.ms-excel"); 
// header("Content-Disposition:filename=test.xls"); 
header("Content-Disposition:attachment;filename=test_data.xls");
$username=checkstr($_GET['username']);
$time1=$_GET['time1'];
$time2=$_GET['time2'];
$filter="where 1=1 ";
if (trim($username)!="") $filter.=" and bname='".trim($username)."'";
if (trim($time1)!="") $filter.=" and btime>='".strtotime($time1)."'";
if (trim($time2)!="") $filter.=" and btime<='".(strtotime($time2)+3600*24)."'";

$db->query("select * from ld_order $filter order by id desc");
$list=$db->rs;
if(!$list){
	return;
}

echo "订单编号\t";echo "用户名\t";echo "商品名称\t";echo "数目\t";echo "总价格\t";
echo "收货人\t";echo "电话\t";echo "地址\t";echo "属性\t";echo "状态\t";echo "购买时间\t\n";
foreach ($list as $key => $rs) {
	if($rs['status']==1){
		 $status='未发货';
	}elseif($rs['status']==2){
		$status='已发货';
	 }else{
	   $status='已签收';
	 }

	echo $rs['id']."\t"; 
	echo $rs["bname"]."\t"; 
	
	$db->query("select * from ld_product where id=".$rs['bpid'],2);
	$req=$db->rs;
	echo $req['productname']."\t";
	echo $rs['bnum']."\t";
	echo $rs['bnum']*$rs["bprice"]."\t";
	echo $rs["bsname"]."\t";
	echo $rs["bphone"]."\t";
	echo $rs["baddress"]."\t";
	echo $rs['sx']."\t";
	echo $status."\t";
	echo date("Y-m-d H:i",$rs["btime"])."\t\n";
}

?> 